// 构建自定义的选择框
import 'package:environmental_les_app/common/style/colours.dart';
import 'package:environmental_les_app/common/widgets/rich_text.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';

Widget buildCustomCheckbox(bool isSelected) {
  return Container(
    width: 22,
    height: 22,
    decoration: BoxDecoration(
      color: isSelected ? Colours.appMain : Colors.white,
      shape: BoxShape.circle,
      border:
          isSelected ? null : Border.all(color: Colours.textC9CDD4, width: 1.5),
    ),
    child: isSelected
        ? const Icon(Icons.check, color: Colors.white, size: 16)
        : null,
  );
}

// 构建角色标签
Widget buildRoleTag(String role) {
  return Container(
    padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
    decoration: BoxDecoration(
      color: Colours.bgF4F7FE,
      borderRadius: BorderRadius.circular(2.4),
      border: Border.all(color: Colours.lineB7C0D7, width: 0.8),
    ),
    child: Text(
      role,
      style: const TextStyle(
        color: Colours.appMain,
        fontSize: 13,
      ),
    ),
  );
}

// 构建人员列表中的单项
Widget buildPersonListItem(
    Map<String, dynamic> person, bool isSelected, VoidCallback onTap) {
  return GestureDetector(
    onTap: onTap,
    child: Container(
      margin: const EdgeInsets.only(bottom: 10),
      padding: const EdgeInsets.all(12),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.0),
        border: Border.all(
          color: isSelected ? Colours.appMain : Colors.transparent,
          width: 1.5,
        ),
      ),
      child: Row(
        children: [
          // 自定义的选择框
          buildCustomCheckbox(isSelected),
          const SizedBox(width: 16),
          // 人员信息
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  // 角色标签
                  buildRoleTag(person['role']),
                  const SizedBox(width: 8),
                  // 姓名
                  Text(
                    person['name'],
                    style: const TextStyle(
                      fontSize: 16,
                      color: Colours.textC4C,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ],
              ),
              const SizedBox(height: 6),
              // 部门信息
              RichTextWidget(children: [
                TextSpan(
                    text: person['department'],
                    style: const TextStyle(
                        fontSize: 12,
                        color: Colours.text09C,
                        fontWeight: FontWeight.w400)),
                TextSpan(
                    text: person['location'],
                    style: const TextStyle(
                        fontSize: 12,
                        color: Colours.appMain,
                        fontWeight: FontWeight.w400)),
              ])
            ],
          ),
        ],
      ),
    ),
  );
}
